<template>
  <div class="login">
    <div class="login_form">
     <div class="login_title">
       <h2>抖音电商后台管理页面</h2>
     </div>
      <div class="login_left">
        <img src="../assets/logo.jpg" alt="">
      </div>
      <div class="login-input">
        <el-form :model="form" :rules="rules" ref="loginForm">
          <el-form-item  prop="username">
            <!--          账号-->
            <el-input prefix-icon='el-icon-user-solid' v-model="form.username" class="login-el-input"></el-input>
          </el-form-item>
          <el-form-item prop="password">
              <!--          密码-->
            <el-input  v-model="form.password" show-password class="login-el-input" prefix-icon='el-icon-lock'></el-input>
          </el-form-item>
            <!--            登录-->
          <el-form-item>
            <el-button @click="login" >登录</el-button>
          </el-form-item>
        </el-form>
      </div>
  </div>
  </div>
</template>
<script>
export  default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          {required: true, message: '账号不能为空', trigger: 'blur'},
          {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '密码不能为空', trigger: 'blur'},
          {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}
        ],
      },
      }
    },
  methods:{
    login(){
      this.$refs.loginForm.validate(async valid =>{
        if (valid){
          const { data:res}= await this.$http.post('/login',this.form)
         if (res.meta.status ===200){
           this.$message({
             message: '恭喜你，登录成功',
             type: 'success'
           });
           window.sessionStorage.setItem('token',res.data.token)
           await this.$router.push('/home');
         }else {
           this.$message.error(res.meta.msg)
         }
        }
      })
    }
  }
  }
</script>
<style scoped>
.login {
  height: 100%;
  width: 100%;
  background-color: #2E2D3C;
  display: flex;
  flex-direction:row;
  justify-content: center;
  align-items: center;
  background-image: url("../assets/3.jpg");
  background-repeat: no-repeat;
  background-size: 100% 100%;

}
.login_form{
  width: 700px;
  height: 300px;
  background-color:whitesmoke;
  opacity: 92%;
  position: relative;
  top:60px;
  border-radius: 20px;
}
.login_title{
  text-align: center;
  padding-top: 20px;
}
.login_left{
  float: left;
  margin-left: 50px;
  margin-top: 20px;
}
.login_left img{
  width:250px;
}
.login-input{
  height: 130px;
  width: 300px;
  float: right;
  border-left: #1E9FFF 2px solid;
  padding-left: 30px;
  margin-right: 50px;
  margin-top: 20px;
}
</style>
